# /usr/bin/python3
# -*- coding: utf-8 -*-
# @Time    : 2022/1/15 10:20
# @Author  : lt
# @Email   : lt@163.com
# @File    : page_HaoWu Society.py
# @Software: PyCharm

from pages.page_base import PageBase
from selenium.webdriver.common.by import By
from time import sleep

class PageConcentration(PageBase):
    search_locator = (By.XPATH,'//android.widget.EditText[@resource-id=\"com.gfeng.daydaycook:id/searchEt\"]')#定位 食谱搜索框
    cookery_book_locator = (149,634)#定位食谱的坐标
    comment_button_locator = (62,1242)#定位评论按钮
    comment_textbox_locator = ('new UiSelector().textStartsWith("我有话要说")')#定位评论输入框
    send_comment_locator = ('new UiSelector().textContains("发送")')#定位发送评论按钮
    username_button_locator = ('new UiSelector().textContains("煮米FbyQld")')#定位用户元素
    confirm_delete_locator = ('new UiSelector().textContains("确认删除")')#定位确认删除按钮
    comment_input = '"哎哟还不错哦"'#输入的内容
    input = f'new UiSelector().textContains({comment_input})'



    def ele_search_click(self,goods):
        '''点击搜索输入框'''
        self.driver.find_element(*self.search_locator).send_keys(goods)
        sleep(2)
        self.driver.keyevent(66)

    def ele_cookery_book(self):
        '''点击食谱'''
        self.driver.tap([(self.cookery_book_locator)])

    def ele_commment_button(self):
        '''点击评论按钮'''
        self.driver.tap([(self.comment_button_locator)])

    def ele_comment_textbox(self,mesage):
        '''输入评论内容'''
        self.driver.find_element_by_android_uiautomator(self.comment_textbox_locator).send_keys(mesage)

    def ele_send_comment(self):
        '''点击发送评论'''
        self.driver.find_element_by_android_uiautomator(self.send_comment_locator).click()

    def ele_username_button(self):
        '''定位用户元素'''
        self.driver.find_element_by_android_uiautomator(self.username_button_locator).click()

    def ele_confirm_delete(self):
        '''定位确认删除按钮'''
        self.driver.find_element_by_android_uiautomator(self.confirm_delete_locator).click()



    def search(self,goods):
        '''搜索功能'''
        self.ele_search_click(goods)
        sleep(3)

    def comment(self,mesage):
        '''评论功能'''
        sleep(3)
        self.ele_cookery_book()
        sleep(5)
        self.ele_commment_button()
        sleep(5)
        self.ele_comment_textbox(mesage)
        sleep(5)
        self.ele_send_comment()
        sleep(10)
        self.driver.tap([(526,428)],500)
        sleep(5)
        text = self.driver.find_element_by_android_uiautomator(self.input).get_attribute('text')
        return text

    def delete_comment(self):
        '''删除评论功能'''
        sleep(2)
        self.ele_cookery_book()
        sleep(3)
        self.ele_commment_button()
        sleep(2)
        self.driver.swipe(400, 1100, 400, 300)
        sleep(3)
        self.ele_username_button()
        sleep(3)
        self.ele_confirm_delete()

